package cn.edu.bcu.ls.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.bcu.ls.entity.User;
import cn.edu.bcu.ls.serviceImpl.UserService;
import io.swagger.annotations.ApiOperation;

@RestController
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 增加用户
	 * @param user
	 * @return
	 */
	@ApiOperation(value = "添加用户，传入你想要的传的值就行")
	@PostMapping(value="User")
	public boolean insertUser(User user) {
		if (userService.insertSelective(user) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	 @ApiOperation(value = "删除用户，传入id")
	 @DeleteMapping(value="User/{u_id}")
	 public boolean deleteUser(@PathVariable("u_id") String u_id) {
		 if (userService.deleteByPrimaryKey(u_id) >0) {
				return true;
			}else {
				return false;
			}
	 }
	 
	 @ApiOperation(value="修改用户信息，传入id和想修改的值")
	 @PutMapping(value="User")
	 public boolean updateUser(User user) {
		 if (userService.updateByPrimaryKeySelective(user) >0) {
				return true;
			}else {
				return false;
			}
	 }
	 @ApiOperation(value="查看单个user传入id")
	 @GetMapping(value="User/{u_id}")
	 public User queryUser(@PathVariable("u_id") String u_id) {
		 return userService.selectByPrimaryKey(u_id);
		 
	 }
	
}
